﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void printArraySort(int arr[], int len)
{
	for (int i = 0; i < len; ++i)
	{
		printf("1.输出数组arr的元素：%d\n", arr[i]);
	}
}
void insertSort(int arr[], int len)
{
	for (int i = 1; i < len; ++i)
	{
		//if (arr[i] < arr[i - 1])
		//2.降序插入排序数组；
		if (arr[i] > arr[i - 1])
		{
			int temp = arr[i];
			int j = i - 1;
			//for (; j >= 0 && temp < arr[j]; j--)
			for (; j >= 0 && temp > arr[j]; j--)
			{
				arr[j + 1] = arr[j];
			}
			arr[j + 1] = temp;
		}
	}
}
void testInsertSort()
{
	int arr[] = { 5,3,9,2,1,3 };
	int len = sizeof(arr) / sizeof(int);
	printArraySort(arr, len);//5,3,9,2,1,3 
	printf("----------------------------------\n");
	insertSort(arr, len);
	printArraySort(arr, len);//1,2,3,3,5,9 --> 9,5,3,3,2,1
}

//main231：插入排序降序
int main231()
{
	testInsertSort();

	system("pause");
	return EXIT_SUCCESS;
}